/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.controller;

import grest.model.DataIO;
import grest.view.FormMozos;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;

/**
 *
 * @author santiago
 */
public class CntrlrFormMozosTxt implements  KeyListener {
    private FormMozos form;
    public CntrlrFormMozosTxt(FormMozos form) {
        this.form=form;
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {

    }

    @Override
    public void keyReleased(KeyEvent e) {
        try{
            Integer nro = Integer.parseInt(((JTextField)form.getControls("txtNroMozo")).getText());
            form.getCntrlr().filtrarMesas(nro);
            try{
                ResultSet rs=DataIO.getResultSet("select apellido||' '||nombre as nombre from t_mozos where nro_mozo="+nro);
                rs.next();
                ((JLabel)form.getControls("lblNombreMozo")).setText(rs.getString("nombre"));
                try {
                    form.setMozoActual(nro);
                } catch (Exception ex1) {
                }
            }catch(SQLException ex){
                try {
                    form.setMozoActual(FormMozos.MOZO_NO_SELECC);
                } catch (Exception ex1) {
                }
            }
        }catch(NumberFormatException ex){
                try {
                    form.setMozoActual(FormMozos.MOZO_NO_SELECC);
                } catch (Exception ex1) {
                }
        }
    }
    
}
